/**
 * Created by macbookair on 2019/5/12.
 */

$(function () {


    $('.sexbtn').on('click', function () {

        var $s = $(this).parent();
        $s.find('.sexbtn').removeClass('active');

        $(this).addClass('active');
    })


    $('.updatebtn').on('click', function () {
        var formdata = new FormData();
        formdata.append("pic", $('#hpic')[0].files[0]);
        var url = $('#himg').attr("src");
        console.log(url);
        if ($('#hpic')[0].files[0] != undefined) {
            $.ajax({
                type: 'POST',
                url: '/cl/uploadheadpic',
                data: formdata,
                contentType: false,
                processData: false,
                success: function (data) {
                    console.log(data);
                    var nickname = $('.nickname').val();
                    var des = $('.des').val();
                    var sex = $('.active').html();
                    console.log(sex);
                    var json = {
                        nickname: nickname,
                        usign: des,
                        usex: sex,
                        uheadpicurl: data,
                    }
                    $.ajax({
                        type: 'POST',
                        url: '/cl/changeSelf',
                        data: JSON.stringify(json),
                        contentType: "application/json",
                        method: "POST",
                        success: function (data) {
                            alert("修改成功");
                            window.location.href = "/cl/selfBlog";
                        }
                    })
                }
            })
        } else {
            var nickname = $('.nickname').val();
            var des = $('.des').val();
            var sex = $('.active').html();
            var json = {
                nickname: nickname,
                usign: des,
                usex: sex,
                uheadpicurl: url.substring(1),
            }
            $.ajax({
                type: 'POST',
                url: '/cl/changeSelf',
                data: JSON.stringify(json),
                contentType: "application/json",
                method: "POST",
                success: function (data) {
                    alert("修改成功");
                    window.location.href = "/cl/selfBlog";
                }
            })
        }
    })
})

$(function () {
    var checkmusicshow = 0;
    var checkmusiclist = 0;
    var checkgallery = 0;
    $(".updateblogbtn").on('click', function () {
        if ($("input[name='checkbox1']").is(':checked') ){
            checkmusiclist=1;
        }
        if($("input[name='checkbox2']").is(':checked') ){
            checkgallery=1;
        }
        if($("input[name='checkbox3']").is(':checked') ){
            checkmusicshow=1;
        }
        var flink = $(".flink").val();
        var articlenum = $("#articlenum").val();
        var blogpic=$(".blogpic")[0].files[0];
        console.log(blogpic+"opoooooooooooooooo");
        var formdata=new FormData;
        formdata.append("musicshow",checkmusicshow);
        formdata.append("musiclist",checkmusiclist);
        formdata.append("gallery",checkgallery);
        formdata.append("link",flink);
        formdata.append("articlenum",articlenum);
        formdata.append("blogpic",blogpic);
        $.ajax({
            type: 'POST',
            url: '/cl/modifyUserBlog',
            data: formdata,
            contentType:false,
            processData:false,
            success: function (data) {
                alert("修改成功");
                window.location.href = "/cl/selfBlog";
            }
        })
    })

})